﻿using XamlInspector.Foundation;
using XamlInspector.Model;
using XamlInspector.Services;

namespace XamlInspector.Presentation
{
    public class MainViewModel : ViewModelBase
    {
        private XamlElement _selectedElement;

        public MainViewModel(VisualTreeService visualTreeService, EventViewModel eventViewModel, PropertiesViewModel propertiesViewModelViewModel, XamlViewModel xamlViewModel)
        {
            VisualTree = visualTreeService.GetVisualTree();
            EventViewModel = eventViewModel;
            PropertiesViewModel = propertiesViewModelViewModel;
            XamlViewModel = xamlViewModel;

            DataContextViewModel = DependencyContainer.Instance.ResolveNew<PropertiesViewModel>();
            DataContextViewModel.IsDataContext = true;
        }

        public XamlTreeModel VisualTree { get; private set; }

        public XamlElement SelectedElement
        {
            get { return _selectedElement; }
            set
            {
                ChangeAndNotify(value, ref _selectedElement);
                EventViewModel.UpdateSelectedElement(value);
                PropertiesViewModel.UpdateSelectedElement(value);
                DataContextViewModel.UpdateSelectedElement(value);
                XamlViewModel.UpdateSelectedElement(value);
            }
        }

        public PropertiesViewModel PropertiesViewModel { get; private set; }
        public PropertiesViewModel DataContextViewModel { get; private set; }

        public XamlViewModel XamlViewModel { get; private set; }

        public EventViewModel EventViewModel { get; private set; }
    }
}
